package com.loadServlet;


import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequestEvent;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import entities.Users;
import com.util.HbnUtil;

public class AddAllProductsToServletContext extends HttpServlet {
	public static ServletContext sc;
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void init() throws ServletException {
		sc=this.getServletContext();
		Session session=null;
		try{
			session=HbnUtil.getSession();
			session.beginTransaction();
			List<Users> list=session.createQuery("from Product").list();
			sc.setAttribute("allProducts",list);
			System.out.println(sc+"aaaaaaaaaaaaaaaaaaaaaaaa");
		
			session.beginTransaction().commit();
		}catch(Exception e){
			e.printStackTrace();
			session.beginTransaction().rollback();
		}finally{
			HbnUtil.releaseSession(session);
		}
		
	}

}
